private function TimeDifference(time1, time2) result(seconds)
calculate the difference in seconds between two date: time1 - time2
Arguments
Type |
Intent | Optional | Attributes |
|
Name |
|
type(DateTime),
|
intent(in) |
|
|
:: |
time1 |
|
type(DateTime),
|
intent(in) |
|
|
:: |
time2 |
|
Return Value
integer(kind=long)
Variables
Type |
Visibility | Attributes |
|
Name |
| Initial | |
integer(kind=long),
|
public |
|
:: |
a |
|
|
|
integer(kind=long),
|
public |
|
:: |
b |
|
|
|
integer(kind=long),
|
public |
|
:: |
c |
|
|
|
integer(kind=short),
|
public |
|
:: |
i |
|
|
|
type(DateTime),
|
public |
|
:: |
tempTime1 |
|
|
|
type(DateTime),
|
public |
|
:: |
tempTime2 |
|
|
|
Source Code
FUNCTION TimeDifference &
!
(time1, time2) &
RESULT (seconds)
USE Units, ONLY: &
! Imported parameters:
day
IMPLICIT NONE
! Arguments with intent(in):
TYPE (DateTime), INTENT(IN) :: time1, time2
! Local variables:
INTEGER (KIND = long) :: seconds, a, b, c
INTEGER (KIND = short) :: i
TYPE (DateTime) :: tempTime1, tempTime2
!------------end of declaration------------------------------------------------
!converto to utc
tempTime1 = ToUtc (time1)
tempTime2 = ToUtc (time2)
a = SecondOfYear (tempTime1)
b = SecondOfYear (tempTime2)
c = 0
DO i = tempTime2 % year, tempTime1 % year - 1
IF (IsLeapYear (i)) THEN
c = c + 366 * day
ELSE
c = c + 365 * day
END IF
END DO
seconds = a + c - b
END FUNCTION TimeDifference